package cn.acmenms.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: AuthorityFilter
 * @Description: 全局的权限过滤器
 * @author: 神奇的鸭鸭
 * @Date: 2017/12/6 13:52
 */
public class AuthorityFilter implements Filter {

    private Logger logger = LoggerFactory.getLogger(AuthorityFilter.class);

    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        // TODO 权限过滤

        Map<String, String> map = new HashMap<>();
        Enumeration headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = req.getHeader(key);
            map.put(key, value);
        }
        System.out.println(map);

        chain.doFilter(req,resp);
    }

    public void destroy() {
    }
}